//
//  WebServiceInterface.m
//  Feeder
//
//  Created by Diego Acosta on 7/30/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "WebServiceInterface.h"


@interface WebServiceInterface(Private)

- (void)_authorize;

@end

@implementation WebServiceInterface

- (id)init {

	if (self = [super init]) {
		
		// initialize instance vars.
		auth = nil;
		_network = nil;
	}
	
	return self;
}

#pragma mark -
#pragma mark Private methods

- (void)_authorize {

	// check if this is an auth call.
	if (auth != nil) {
		
		NSString * _auth = [NSString stringWithFormat:@"GoogleLogin auth=%@", auth];
		[_network addRequestHeader:@"Authorization" value:_auth];
	}
}

#pragma mark -
#pragma mark Protected methods

- (void)_submitWithURL:(NSString *)url andMethod:(HTTPMethod)method {
	
	NSURL * _url = [NSURL URLWithString:url];
	NSString * _method = [WebServiceHelper stringFromServiceMethod:method];
	
	_network = [[ASIHTTPRequest requestWithURL:_url] retain];
	
	// request configuration.
	[_network setDelegate:service];
	[_network setRequestMethod:_method];
	
	// authentication.
	[self _authorize];
	
	[_network startAsynchronous];
}

#pragma mark -

- (void)dealloc {
	
	[auth release];
	[_network release];
	[super dealloc];
}

@end
